package com.situ.blog.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
 * 跳转页面
 * 所有jsp页面 都要通过 PageController 进行跳转
 * 所有的jsp都放在/WEB-INF/page文件夹下
 * localhost:8081/page/blog、/page/user、/page/auth
 */
@WebServlet("/page/*")
public class PageController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String servletPath = req.getServletPath();
        // /page
        System.out.println("servletPath: " + servletPath);
        // /page/blog
        String requestURI = req.getRequestURI();
        System.out.println("requestURI: " + requestURI);
        String pageURI = requestURI.substring(requestURI.lastIndexOf("/"));
        req.getRequestDispatcher("/WEB-INF/page/"+pageURI+".jsp").forward(req, resp);
    }
}
